<?php
function getEntpHeader($pu,$ep) {
	global $objSDAO;
	$sSQL = "SELECT e.*, p.module "
		.",p.description as pdes, m.description AS mdes, s.functional_area, " .
		"	f.description AS fdes, s.description AS sdes, s.sub_module " .
		" FROM entry_point e ".
		" LEFT JOIN process_unit p ON p.process_unit = e.process_unit" .
		" LEFT JOIN module m ON m.module = p.module " .
		" LEFT JOIN sub_module s ON s.module = p.module " .
		"    AND s.sub_module = p.sub_module " .
		" LEFT JOIN functional_area f ON f.module = p.module " .
		"    AND f.functional_area = s.functional_area " .
		" WHERE e.process_unit = '".$pu."' AND e.entry_point = ".intval($ep);
	$objSDAO->query($sSQL, "procHead");
	$row = $objSDAO->fetch("procHead");
	
	$sHtml = ("<table width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n<tr>\n<td>\n");
	$sHtml .= ("<tr>" .
			"<td class=\"titl01\" width=\"15%\">Module</td>" .
			"<td class=\"text01\" width=\"85%\" style='font-weight:bold;'>".$row['module']." - ".$row['mdes']."</td>" .
		"</tr>\n");
	/*/////////////
	$sHtml .= ("<tr>" .
			"<td class=\"titl01\">Functional-Area</td>" .
			"<td class=\"text01\" style='font-weight:bold;'>".$row['functional_area']." - ".$row['fdes']."</td>" .
		"</tr>\n");
	//*////////////////////
	$sHtml .= ("<tr>" .
			"<td class=\"titl01\">Sub-Module</td>" .
			"<td class=\"text01\" style='font-weight:bold;'>".$row['sub_module']." - ".$row['sdes']."</td>" .
		"</tr>\n");
	$sHtml .= ("<tr>" .
			"<td class=\"titl01\">Process-unit</td>" .
			"<td class=\"text01\" style='font-weight:bold;'>".$row['process_unit']." - ".$row['pdes']."</td>" .
		"</tr>\n");
	$sHtml .= ("<tr>" .
			"<td class=\"titl01\">Entry-point</td>" .
			"<td class=\"text01\" style='font-weight:bold;'>".str_pad($row['entry_point'],4,'0',STR_PAD_LEFT)
			." - ".$row['description']."</td>" .
		"</tr>\n");
	$sHtml .= ("</table>\n");
	return $sHtml;
}

function getVarAbil($processUnit, $entriPoint) {
	global $objSDAO;
	$aVarAbil = array(); 
	$sSQL = "SELECT ali.alias, a.attribute, IFNULL(pat.read_only,ali.read_only) AS read_only" .
			" FROM entry_point_alias epa " .
			" INNER JOIN pu_alias ali ON ali.process_unit = epa.process_unit AND ali.alias = epa.alias " .
			" INNER JOIN attribute a ON a.entity = ali.entity " .
			" LEFT JOIN pu_attribute pat ON pat.process_unit = epa.process_unit AND pat.alias = epa.alias " .
			"    AND pat.entity = a.entity AND pat.attribute = a.attribute " .
			" WHERE epa.process_unit='$processUnit' " .
			"    AND epa.entry_point='$entriPoint'";	
	$objSDAO->query($sSQL,"x");
	while($row = $objSDAO->fetch('x')) {
		$aVarAbil[$row['alias'].'_'.$row['attribute']] = $row['read_only'];
	}
	$sSQL = "SELECT ali.alias, pv.variable " .
			" FROM entry_point_alias epa " .
			" INNER JOIN pu_alias ali ON ali.process_unit = epa.process_unit AND ali.alias = epa.alias " .
			" INNER JOIN pu_variable pv ON pv.process_unit = epa.process_unit AND pv.alias = epa.alias  " .
			" WHERE epa.process_unit='$processUnit' " .
			"    AND epa.entry_point='$entriPoint'";	
	$objSDAO->query($sSQL,"x");
	while($row = $objSDAO->fetch('x')) {
		$aVarAbil[$row['alias'].'_'.$row['variable']] = 'N';
	}
	return $aVarAbil;
}

function getFunzDisp($processUnit) {
	global $objSDAO;
	$aFunzDisp = array(); 
	$sSQL = "SELECT f.result_type, f.function, f.library ,fv.variable_type " .
			" FROM `function` f " .
			" LEFT JOIN function_variable fv ON fv.function = f.function  " .
			" ORDER BY f.function, fv.sequence";	
	$objSDAO->query($sSQL,"x");
	while($row = $objSDAO->fetch('x')) {
		if (!isset($aFunzDisp[$row['function']])) {
			$aFunzDisp[$row['function']] = array();
		}
		if (!empty($row['variable_type'])) {
			$aFunzDisp[$row['function']][]=$row['variable_type'];
		}
	}
	return $aFunzDisp;
}
